<?php
	if (!(function_exists('login_ex'))){
		$smarty->template_dir = $setupdata['smarty_admin_template_dir'];
		$smarty->display('admin/login.tpl');
		$mysqlclass->close_db();
		include $setupdata['core_dir']."/includes/die.php";
	}

	if (!isset($_GET['id'])) $id=NULL; else $id=$_GET['id'];
	if ($id==NULL) if (!isset($_POST['id']) || (isset($_POST['id']) && ($_POST['id']==''))) $id=0; else $id=$_POST['id'];
 	if (!isset($_GET['act'])) $act=NULL; else $act=$_GET['act'];
	if ($act==NULL) if (!isset($_POST['act'])) $act=NULL; else $act=$_POST['act'];
	if (!isset($_GET['mod'])) $mod=NULL; else $mod=$_GET['mod'];
	if ($mod==NULL) if (!isset($_POST['mod'])) $mod=NULL; else $mod=$_POST['mod'];
	if (!isset($_GET['parent'])) $parent=NULL; else $parent=$_GET['parent'];
	if ($parent==NULL) if (!isset($_POST['parent'])) $parent=NULL; else $parent=$_POST['parent'];
	if (!isset($_GET['name'])) $name=NULL; else $name=$_GET['name'];
	if ($name==NULL) if (!isset($_POST['name'])) $name=NULL; else $name=$_POST['name'];

	include($setupdata['core_dir']."/includes/setlang.php");
	$data['tree']['lng']['cur']=$lang; 
	
	if ($mod=="files"){
		if ($act == 'del'){
			$imageclass->flash_del($id);
		}elseif ($act == 'name_mod') {
			$imageclass->image_mod_name($id, $name, $_SESSION['login_user']);
		}elseif ($act == 'add'){
			if (isset($_POST['add_more']) && ($_POST['add_more'] == 1)){
				for ($i=1; $i<=14; $i++){
					if ($i < 10) $x_name = "0".$i;
					else $x_name = $i;
					$file = $_FILES["img_file".$x_name];
					$file_name1 = $_POST["img_name".$x_name];
					$v = $file['tmp_name'];
					if ($v != ""){
						if (isset($setupdata['file_size']) && ($file['size']/1024 > $setupdata['file_size'])) $err->AddError(28);
						else {
							$imagedata = getimagesize($v);
							if (($imagedata[2] == 4) || ($imagedata[2] == 13)){
								$today = uniqid("");
								$name = $parent."-".$today."-".$imagedata[0]."x".$imagedata[1].".swf";
								$file_to = $name;
								if (strlen($file_name1) <= 0) $file_name1=$file['name'];
								if (!(file_exists($setupdata['binary_path']."/".$parent))){
									mkdir($setupdata['binary_path']."/".$parent, 0777);
									if (file_exists($setupdata['binary_path']."/".$parent)){
										if (copy($file['tmp_name'], $setupdata['binary_path']."/".$parent."/".$file_to)){
											if (file_exists( $setupdata['binary_path']."/".$parent."/".$file_to)){
												chmod($setupdata['binary_path']."/".$parent."/".$file_to, 0666);
												$v = $imageclass->flash_add($file, $file_name1, $file_to, $parent, $imagedata[0], $imagedata[1], $_SESSION['login_user']);
											}
										}
									}
								} else {
									if (copy($file['tmp_name'], $setupdata['binary_path']."/".$parent."/".$file_to)){
										if (file_exists($setupdata['binary_path']."/".$parent."/".$file_to)){
											chmod($setupdata['binary_path']."/".$parent."/".$file_to, 0666);
											$v = $imageclass->flash_add($file, $file_name1, $file_to, $parent, $imagedata[0], $imagedata[1], $_SESSION['login_user']);
										}
									}
								}
							}
						}
					}	
				}					
			} else {
				$file = $_FILES['img_file1'];
				$file_name1 = $_POST['img_name1'];
				$v = $file['tmp_name'];
				if ($v != ""){
					if (isset($setupdata['file_size']) && ($file['size']/1024 > $setupdata['file_size'])) $err->AddError(28);
					else {
						$imagedata = getimagesize($v);
						if (($imagedata[2] == 4) || ($imagedata[2] == 13)){
							$today = uniqid("");
							$name = $parent."-".$today."-".$imagedata[0]."x".$imagedata[1].".swf";
							$file_to = $name;
							if (strlen($file_name1) <= 0) $file_name1=$file['name'];
							if (!(file_exists($setupdata['binary_path']."/".$parent))){
								mkdir($setupdata['binary_path']."/".$parent, 0777);
								if (file_exists($setupdata['binary_path']."/".$parent)){
									if (copy($file['tmp_name'], $setupdata['binary_path']."/".$parent."/".$file_to)){
										if (file_exists( $setupdata['binary_path']."/".$parent."/".$file_to)){
											chmod($setupdata['binary_path']."/".$parent."/".$file_to, 0666);
											$v = $imageclass->flash_add($file, $file_name1, $file_to, $parent, $imagedata[0], $imagedata[1], $_SESSION['login_user']);
										}
									}
								}
							} else {
								if (copy($file['tmp_name'], $setupdata['binary_path']."/".$parent."/".$file_to)){
									if (file_exists($setupdata['binary_path']."/".$parent."/".$file_to)){
										chmod($setupdata['binary_path']."/".$parent."/".$file_to, 0666);
										$v = $imageclass->flash_add($file, $file_name1, $file_to, $parent, $imagedata[0], $imagedata[1], $_SESSION['login_user']);
									}
								}
							}
						}
					}
				}						
				$p = $parent;
			}
		}
	}

/*
	if ($mod == 'all') $data['flash_galer'] = $imageclass->flash_sel(0);
	else $data['flash_galer'] = $imageclass->flash_sel($parent);
	for ($i=0; $i < count($data['flash_galer']); $i++){
		$data['flash_galer'][$i]['size'] = $imageclass->image_size($data['flash_galer'][$i]['id']);
	}
*/

	if (isset($act)) {
		require ($setupdata['core_dir'].'/includes/referer.php');
	} else {
		$smarty->template_dir = $setupdata['smarty_admin_template_dir'];
		$smarty->assign("_http_path", $setupdata['base_href']);
		$smarty->assign("data", $data);
		$smarty->display('admin/insflash.tpl');
	}
?>
